package org.kazminov.mywakeupper;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
 * Created with IntelliJ IDEA.
 * User: olkazmin
 * Date: 12/1/12
 * Time: 7:15 AM
 * To change this template use File | Settings | File Templates.
 */
public class WakeEventsReceiver extends BroadcastReceiver {

    public static final String ACTION_MY_WAKE_UP = "org.kazminov.mywakeupper.ACTION_MY_WAKE_UP";

    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();

        if (action.equalsIgnoreCase(ACTION_MY_WAKE_UP)) {
            final Intent serviceIntent = new Intent(context, WakeService.class);
            serviceIntent.setAction(ACTION_MY_WAKE_UP);
            context.startService(serviceIntent);
        } else if (action.equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)
                || action.equalsIgnoreCase(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {
            final Intent serviceIntent = new Intent(context, WakeService.class);
            serviceIntent.setAction(WakeService.ACTION_START);
            context.startService(serviceIntent);
        } else if (action.equalsIgnoreCase(WakeService.ACTION_START)) {
            final Intent serviceIntent = new Intent(context, WakeService.class);
            serviceIntent.setAction(WakeService.ACTION_START);
            context.startService(serviceIntent);
        }
    }
}
